package com.pllandxzx.controller;

import com.pll.pojo.Role;
import com.pllandxzx.dto.ResponseDTO;
import com.pllandxzx.service.MerchantService;
import com.pllandxzx.vo.CheckVo;
import com.pllandxzx.vo.MerchantVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName：MerchantController
 * @Author: 阿⭐
 * @Date: 2025/6/12 11:41
 * @Description: TODO
 */
@Tag(name = "商家管理")
@RestController
@RequestMapping("/merchant")
public class MerchantController {
    @Autowired
    private MerchantService merchantService;

    @Operation(summary = "商家信息列表", description = "获取商家信息列表，支持营业执照以及商家地址动态查询")
    @GetMapping("/list")
    public ResponseDTO getList(MerchantVo merchantVo){
        return merchantService.getMerchantList(merchantVo);
    }

    @Operation(summary = "商家详情列表", description = "获取对应id商家信息详情")
    @GetMapping("/{id}")
    public ResponseDTO getMerchantDetail(@PathVariable("id")long id){
        System.out.println(id);
        return merchantService.getMerchantDetail(id);
    }

    @Operation(summary = "商家评论列表", description = "获取对应id商家的评论")
    @GetMapping("/{id}/comments")
    public ResponseDTO getMerchantComments(@PathVariable("id")long id){
        System.out.println(id);
        return merchantService.getMerchantComments(id);
    }

    @Operation(summary = "删除评论", description = "根据评论id，删除评论")
    @DeleteMapping("/comment/{reviewId}")
    public ResponseDTO deleteMerchantComment(@PathVariable("reviewId") int reviewId){
        return merchantService.deleteMerchantComment(reviewId);
    }

    @Operation(summary = "重置商家密码", description = "根据商家id，重置商家密码")
    @PostMapping("/{id}/reset-password")
    public ResponseDTO resetMerchantPassword(@PathVariable("id") int id){
        return merchantService.resetMerchantPassword(id);
    }

    @Operation(summary = "更新商家状态", description = "根据商家id，更改商家状态，决定启用和封禁商家")
    @PutMapping("/{id}/status")
    public ResponseDTO updateMerchantStatus(@PathVariable("id") int id,@RequestBody MerchantVo merchantVo){

        System.out.println(id +"  "+ merchantVo.getStatus());
         return merchantService.updateMerchantStatus(id,merchantVo.getStatus());
    }


    @Operation(summary = "审核商家信息列表", description = "获取审核商家信息列表，支持营业执照以及商家地址动态查询")
    @GetMapping("/pending")
    public ResponseDTO getCheckList(MerchantVo merchantVo){
        return merchantService.getCheckList(merchantVo);
    }

    @Operation(summary = "商家审核", description = "人工审核商家信息，若审核不通过则需要填写不通过的原因")
    @PostMapping("/{id}/audit")
    public ResponseDTO auditMerchant(@PathVariable("id") long id, @RequestBody CheckVo checkVo){
        return merchantService.auditMerchant(id,checkVo);
    }


}
